
*For Margaret dropbox folders 
global NCREIF "/Users/BeckaBrolinson/Dropbox/NCREIF/data" 
global build 	"$NCREIF/build" 
global analysis "$NCREIF/analysis"
global results 	"$analysis/results"
global figures 	"$analysis/figures" 


*------------------------------------------------------------------------------*
*	Step 7- Matched Summary Stats	   *
*------------------------------------------------------------------------------*	

*Genreate summary statistics: First Pre-Match
	*Make lists of time varying and time invariant variables (recall match on time invar ones) 
	
	#d ; 
	global timevarying 	"rl_yr_utilpersf rl_yr_rentpersf percentleased real_elecprice real_gasprice Unemployment 
	HDD CDD age used_space real_capex_ti real_capex_bldimp"; 
	global timeinvarying "mean_nooffloors mean_noofunits mean_noofbuildings 
	mean_nra mean_sqft mean_yrbuilt
	mean_lastrenovatedyear  mean_yrbuiltorlastren  mean_Covered_E  mean_latitude mean_longitude"; 
	*List of variables that I do summary stats for ; 
	global vars "rl_yr_utilpersf rl_yr_rentpersf sqft yrbuilt Covered_E 
				real_elecprice real_gasprice Unemployment HDD CDD age used_space
				percentleased real_capex_ti real_capex_bldimp dFundType1
				dFundType2 dFundType3 dFundType4 dFundType5 dFundType6"; 
	#d cr 
	
	
	*First, summary stat for pre match, time varying characteristics 
	use "$build/01_annualizeddatawcontrol.dta", clear 
	drop if nra<0 

	gen ttest_var = . 
	replace ttest_var = 1 if treat==1 & post==0 
	replace ttest_var = 0 if treat==0 & year<=2009 

*Pre-match Time Varying 
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==0 & year<=2009, detail
	local ++meanrow
	local ++sdrow
	putexcel B3=("Mean Uncertified Pre 2009 ") A`meanrow'=("`var'") B`meanrow'=(`r(mean)') B`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==1 & post==0 , detail 
	local ++meanrow
	local ++sdrow
	putexcel C3=("Mean Treated Pre-Cert") C`meanrow'=(`r(mean)') C`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==1 & post==1 , detail 
	local ++meanrow
	local ++sdrow
	putexcel D3=("Mean Treated Post-Cert") D`meanrow'=(`r(mean)') D`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	di "ttest of `var'"
	ttest `var', by(ttest_var) welch
	local ++meanrow
	local ++sdrow
	putexcel H3=("(1) - (2)") H`meanrow'=(`r(mu_1)'-`r(mu_2)') I`meanrow'=(`r(p)')
	putexcel I3=("P-Score of Diff.")
	local ++meanrow 
	local ++sdrow
	} 
	
	
	*Now Summary Stat for Post-match, time varying characteristics 
	use "$build/FakeNCREIFAnnualizedDatawcontrol_PostMatch3.dta", clear 
	drop if nra<0 
	
	gen ttest_var = . 
	replace ttest_var = 1 if treat==1 & post==0 
	replace ttest_var = 0 if treat==0 & year<=2009 

*Pre-match Time Varying 
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==0 & year<=2009, detail
	local ++meanrow
	local ++sdrow
	putexcel E3=("Mean Uncertified Pre 2009") E`meanrow'=(`r(mean)') E`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==1 & post==0 , detail 
	local ++meanrow
	local ++sdrow
	putexcel F3=("Mean Treated Pre-Cert") F`meanrow'=(`r(mean)') F`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	su `var' if treat==1 & post==1 , detail 
	local ++meanrow
	local ++sdrow
	putexcel G3=("Mean Treated Post-Cert") G`meanrow'=(`r(mean)') G`sdrow'=(`r(sd)')
	local ++meanrow 
	local ++sdrow
	} 
	
	*Inputs 
	local meanrow "3" 
	local sdrow "4"
	local obsrow "5"
	
	putexcel set "$results/SummaryStat.xlsx", sheet("TTest") modify
	foreach var of global vars{
	di "ttest of `var'"
	ttest `var', by(ttest_var) welch
	local ++meanrow
	local ++sdrow
	putexcel K3=("(1) - (2)") K`meanrow'=(`r(mu_1)'-`r(mu_2)') L`meanrow'=(`r(p)')
	putexcel L3=("P-Score of Diff.")
	local ++meanrow 
	local ++sdrow
	} 
	

